using System;
using System.Collections;

namespace FrameworkX.Collections.Base
{
	/// <summary>
	/// Base class for creating any list. Methods are self explanatory
	/// like any normal list class.
	/// </summary>
	public abstract class ListBase : ICollection, IList, IDisposable
	{
		protected ArrayList _list = new ArrayList();

		protected ArrayList InnerList 
		{
			get
			{				
				return _list;
			}
			set
			{
				_list= value;
			}
		}

		protected virtual void Add( object value )
		{
			_list.Add( value );
		}
		
		public virtual void AddRange( ICollection list )
		{
			_list.AddRange (list);
		}

		public virtual bool Contains( object obj )
		{
			return _list.Contains(obj);
		}

		public virtual void Clear()
		{
			_list.Clear();
		}

		public virtual int Count
		{
			get
			{
				return _list.Count;
			}
		}

		protected virtual object Get( int index )
		{
			return _list[index];
		}

		public virtual IEnumerator GetEnumerator()
		{
			return _list.GetEnumerator();				
		}

		public virtual void CopyTo(Array array, int index)
		{
			_list.CopyTo( array, index );
		}

		public virtual bool IsSynchronized
		{
			get
			{
				return _list.IsSynchronized;
			}
		}

		public virtual void Remove (object obj)
		{
			_list.Remove (obj);
		}

		public virtual void RemoveAt (int pos)
		{
			_list.RemoveAt (pos);
		}

		public virtual object SyncRoot
		{
			get
			{
				return _list.SyncRoot;
			}
		}

		public virtual void Sort()
		{
			_list.Sort();
		}

		public virtual void Sort(IComparer comparer)
		{
			_list.Sort(comparer);
		}
		#region IList Members

		public bool IsReadOnly
		{
			get
			{
				return _list.IsReadOnly;
				return false;
			}
		}

		public object this[int index]
		{
			get
			{
				return this.Get(index);
			}
			set
			{
				_list[index]=value;
			}
		}

		public void Insert(int index, object value)
		{
			_list.Insert(index, value);
		}

		public int IndexOf(object value)
		{
			return _list.IndexOf(value);
		}

		int System.Collections.IList.Add(object value)
		{
			return _list.Add (value);
		}

		public bool IsFixedSize
		{
			get
			{
				return _list.IsFixedSize;
			}
		}

		#endregion

		#region IDisposable Members

		public void Dispose()
		{
			_list.Clear();
			_list = null;
		}

		#endregion
	}
}
